package cn.jiedh.app.meiweidk.Utils.UI;


import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.umeng.analytics.MobclickAgent;

import cn.jiedh.app.meiweidk.MyWebActivity;
import cn.jiedh.app.meiweidk.R;
import cn.jiedh.app.meiweidk.Utils.interfaces.FirstGGcallback;
import cn.jiedh.app.meiweidk.Utils.tool.LoadUtils;
import cn.jiedh.app.meiweidk.entity.IndexPopBean;
import cn.jiedh.app.meiweidk.web.WebActivity;

/**
 * @author PACY
 * 创建时间 19/2/15 09:11.
 * 邮箱 pengwwe457621023@qq.com
 * 类描述 第一次登录弹出的广告dialog
 */
public class FirstGGDialog extends Dialog {
    private Context context;
    ImageView close,image;
    private IndexPopBean bean;
    FirstGGcallback firstGGcallback;
    public FirstGGDialog(Context context,IndexPopBean bean) {
        super(context);
        this.context = context;
        this.bean=bean;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        View view = LayoutInflater.from(context).inflate(R.layout.firstgg_dialog, null);
        close=view.findViewById(R.id.close);
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        image=view.findViewById(R.id.image);
        LoadUtils.loadImage(context,bean.getImgUrl(),image);

        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                WebActivity.launch(bean.getLink(), "详情", context);

                firstGGcallback.onFirstClick();

                MobclickAgent.onEvent(context,"indexPop_click");
                Intent intent = new Intent(context, MyWebActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("title", "详情");
                bundle.putString("url", bean.getLink());
                intent.putExtras(bundle);
                context.startActivity(intent);
                dismiss();
            }
        });

        setCanceledOnTouchOutside(true);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        setContentView(view);
    }

    /**
     * 点击回调 在activity里发送统计请求
     * @param firstGGcallback
     */
    public void setCallback(FirstGGcallback firstGGcallback){
        this.firstGGcallback=firstGGcallback;
    }


}
